package com.conpany.project.MapperTest;

import com.company.project.constant.TradeEnums;
import com.company.project.dao.TradeGoodsMapper;
import com.company.project.dao.TradeMqConsumerLogMapper;
import com.company.project.model.TradeGoods;
import com.company.project.model.TradeMqConsumerLog;
import com.company.project.model.TradePay;
import com.conpany.project.Tester;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.junit.Test;
import tk.mybatis.mapper.entity.Condition;

import javax.annotation.Resource;

public class GoodsMapper extends Tester {

    @Resource
    TradeGoodsMapper tradeGoodsMapper;
    @Resource
    TradeMqConsumerLogMapper tradeMqConsumerLogMapper;


    @Test
    public void name() {

        TradeGoods bwan = tradeGoodsMapper.selectByPrimaryKey(2);
        bwan.setGoodsName("sssssssss");
        int i = tradeGoodsMapper.updateByPrimaryKeySelective(bwan);
        System.out.println( "########## "+ i);
    }

    @Test
    public void test() {
        Condition c = new Condition(TradeGoods.class);
        c.createCriteria()
                .andEqualTo("goodsId",5)
                .andEqualTo("goodsName","jcliang2222");
        long count = this.tradeGoodsMapper.selectCountByCondition(c);
        System.out.println("######  : "+ count );

    }

    @Test
    public void  reduceGoodsNumber(){
//                  mqConsumerLog = this.tradeMqConsumerLogMapper.selectByPrimaryKey(key);

//					TradeMqConsumerLogExample tradeMqConsumerLogExample = new TradeMqConsumerLogExample();
//					tradeMqConsumerLogExample.createCriteria().andGroupNameEqualTo(mqConsumerLog.getGroupName())
//							.andMsgKeyEqualTo(mqConsumerLog.getMsgKey()).andMsgTagEqualTo(mqConsumerLog.getMsgTag())
//							.andConsumerTimesEqualTo(mqConsumerLog.getConsumerTimes());
//                  乐观锁的方式防止并发更新，只有一个处理者能成功
//					int record = this.tradeMqConsumerLogMapper.updateByExampleSelective(updateMqConsumerLog,
//							tradeMqConsumerLogExample);

        TradeMqConsumerLog  mqConsumerLog_6 = this.tradeMqConsumerLogMapper.selectByPrimaryKey(6);
        TradeMqConsumerLog  mqConsumerLog_5 = this.tradeMqConsumerLogMapper.selectByPrimaryKey(5);
        System.out.println("#### mqConsumerLog ="+ mqConsumerLog_6.getId());


        Condition c = new Condition(TradeMqConsumerLog.class);

        TradeMqConsumerLog ss = new TradeMqConsumerLog();
        ss.setMsgKeys("key3");
        ss.setMsgTag("tag2");
        ss.setGroupName("name1");
        ss.setMsgId("555556");

//        c.createCriteria().andEqualTo(groupName,groupName);
//        c.createCriteria().andEqualTo(keys,keys);
//        c.createCriteria().andEqualTo(tags,tags);
//        c.createCriteria().andEqualTo(tags,tags);
//        c.createCriteria().andCondition(" msg_keys = 'key10' and group_name = 'name1' and msg_tag = 'tag577' ");
        c.createCriteria()
                .andEqualTo("msgKeys",mqConsumerLog_6.getMsgKeys())
                .andEqualTo("groupName",mqConsumerLog_6.getGroupName())
                .andEqualTo("msgTag",mqConsumerLog_6.getMsgTag());


//        int record = this.tradeMqConsumerLogMapper.updateByCondition(mqConsumerLog_6,c);
//        int record = this.tradeMqConsumerLogMapper.updateByCondition(mqConsumerLog_6,c);


         int record=0;
        //try {
            TradeMqConsumerLog bean = new TradeMqConsumerLog();
            bean.setMsgKeys("555");
            bean.setMsgTag("555");
            bean.setGroupName("555");
            bean.setMsgId("555");
            this.tradeMqConsumerLogMapper.insert(bean);
            record = this.tradeMqConsumerLogMapper.updateByConditionSelective(ss,c);
            System.out.println("xxxxxxxxxxxxxxx "+record);
       // }catch (Exception e){

       // }
        System.out.println("#### record ="+ record);







    }


}
